//
//  IMessageDataFile.m
//  imessagesender
//
//  Created by Pang lei on 13-7-25.
//  Copyright (c) 2013年 Pang lei. All rights reserved.
//

#import "IMessageDataFile.h"
#import "FileUtils.h"

@implementation IMessageDataFile

@synthesize filename=_filename;
@synthesize taskId=_taskId;
@synthesize tmpDir=_tmpDir;
@synthesize scriptFile=_scriptFile;

- (id)initWithFilename:(NSString *)filename
{
    if((self = [super init])) {
        self.filename = filename;
    }
    return self;
}

- (void)process
{
    NSString *tmpdir = [self getTempDirectoryName];
    self.tmpDir = tmpdir;
    NSString *scriptFile = [NSString stringWithFormat:@"%ld.scpt", [self getTimpstamp]];
    self.scriptFile = [NSString stringWithFormat:@"%@/%@", self.tmpDir, scriptFile];
    [FileUtils createDirectory:tmpdir];
    [FileUtils unzip:self.filename workspace:self.tmpDir];
}

- (NSInteger) getTimpstamp
{
    NSTimeInterval timeStampFloat = [[NSDate date] timeIntervalSince1970];
    NSInteger timeStamp = timeStampFloat;
    return timeStamp;
}

- (NSString *) getTempDirectoryName
{
    NSString *tmpDirectoryName = [NSString stringWithFormat:@"%@", @"/tmp/task_"];
    return [tmpDirectoryName stringByAppendingFormat:@"%ld", [self getTimpstamp]];
}

- (NSString *) getContentXML
{
    NSString *contextXML = [NSString stringWithFormat:@"%@/content.xml", self.tmpDir];
    return contextXML;
}

- (NSString *) getRecipientXML
{
    NSString *recipientXML = [NSString stringWithFormat:@"%@/recipients.xml", self.tmpDir];
    return recipientXML;
}

- (NSString *) getScriptFile
{
    return self.scriptFile;
}

@end
